//测试CubeMap的像素着色器

#version 450
#extension GL_ARB_separate_shader_objects : enable

//输入-从顶点着色器
layout(location = 0) in vec3 vs_fs_normal;
layout(location = 1) in vec3 vs_fs_tangent;
layout(location = 2) in vec2 vs_fs_TexCoord;
layout(location = 3) in vec3 vs_fs_worldPosition;

//输出
layout(location = 0) out vec4 fColor;

//纹理
layout(binding = 9) uniform sampler2D ourTexture;

//UniformBuffer
layout(binding = 7) uniform SceneData {
	mat4 view;
	mat4 proj;
	vec4 lightDir;
	vec4 eyePosition;
} ub_SceneData;

void main()
{
	//光线方向
	vec3 LightDir = ub_SceneData.lightDir.xyz;
	
	//计算法线方向：
	vec3 NormalDir = vec3(0,0,1);
	{
		//切线空间的法线
		vec4 TangentNormal =  texture(ourTexture, vs_fs_TexCoord);
		TangentNormal = TangentNormal * 2 - vec4(1, 1, 1, 1);
	
		//切线空间三轴在模型空间的基向量：
		vec3 BaseN = normalize(vs_fs_normal);
		vec3 BaseT = normalize(vs_fs_tangent);
		vec3 BaseB = cross(BaseT,BaseN);
		
		//模型空间的法线方向：
		NormalDir = BaseT*TangentNormal.x + BaseB*TangentNormal.y + BaseN*TangentNormal.z;
	}
	
	//光线点乘法线
	float NdL = dot(normalize(NormalDir),normalize(LightDir));
	
	//将NdL限定在0到1
	NdL = clamp(NdL,0,1);
	
	//颜色系数
	float c = NdL * 0.7 + 0.3;

	fColor = vec4( c, c, c, 1.0 );
}
